// pages/settings/feedback/feedback.js
var util = require('../../../utils/util.js')
var app = getApp()
const domainUrl = app.globalData.domainUrl


Page({
  data: {
    userInfo: {},
    content: "",
    connect: "",
    openid: ""
  },
  onLoad: function (options) {
    const that = this;
    // 页面初始化 options为页面跳转所带来的参数
    app.getUserInfo(function (userInfo) {
      that.setData({
        userInfo: userInfo
      })
    });

    util.login(this.route);
  },
  getContent: function (e) {
    console.log(e.detail.value);
    this.setData({
      content: e.detail.value
    })
  },
  submitSuggestion: function () {
    const that = this;
    var user = app.globalData.userInfo;
    
    that.data.openid = wx.getStorageSync("my_openid");
    if (null == that.data.openid || null == that.data.openid)     {
      console.log('未登录');
    }

    wx.request({
      url: domainUrl +'feedBack',
      method: 'POST',
      data: {
        content: '【水浒英雄卡】'+this.data.content,
        sex: user.gender,
        nickName: user.nickName,
        headUrl: user.avatarUrl,
        openId: wx.getStorageSync('my_openid')
      }
    }),
      this.setData({
        content: ''
      }),
    wx.showToast({
      title: '问题反馈成功',
      icon: 'success',
      duration: 2000,
      mask: false
    })
  }
  
})